package com.lvcoding.auth2.auth.shizhan.service.impl;

import com.lvcoding.auth2.auth.shizhan.entity.SysUser;
import com.lvcoding.auth2.auth.shizhan.dao.SysUserDao;
import com.lvcoding.auth2.auth.shizhan.service.SysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * (SysUser)表服务实现类
 *
 * @author wys
 * @since 2022-03-22 18:08:11
 */
@RequiredArgsConstructor
@Service
public class SysUserServiceImpl implements SysUserService {

    private final SysUserDao sysUserDao;

    @Override
    public SysUser queryByName(String username) {
        SysUser sysUser = sysUserDao.queryByName(username);
        return sysUser;
    }

    @Override
    public SysUser queryByPhone(String phone) {
        SysUser sysUser = sysUserDao.queryByPhone(phone);
        return sysUser;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SysUser queryById(Long id) {
        return this.sysUserDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<SysUser> queryAllByLimit(int offset, int limit) {
        return this.sysUserDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param sysUser 实例对象
     * @return 实例对象
     */
    @Override
    public SysUser insert(SysUser sysUser) {
        this.sysUserDao.insert(sysUser);
        return sysUser;
    }

    /**
     * 修改数据
     *
     * @param sysUser 实例对象
     * @return 实例对象
     */
    @Override
    public SysUser update(SysUser sysUser) {
        this.sysUserDao.update(sysUser);
        return this.queryById(sysUser.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.sysUserDao.deleteById(id) > 0;
    }

    @Override
    public List<String> queryRoleByUserId(long userId) {
        return this.sysUserDao.queryRoleByUserId(userId);
    }
}
